package com.pro01.redisforum.pojo;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
public class PageResult<T> {
    private List<T> records;
    private long total;

    // 可选分页元信息
    private long totalPages;
    private int pageSize;
    private int currentPage;

    public PageResult(long total, int pageSize, int currentPage, List<T> records) {
        this.total = total;
        this.pageSize = pageSize;
        this.currentPage = currentPage;
        this.totalPages = (total + pageSize - 1) / pageSize;
        this.records = records;
    }

    public static <T> PageResult<T> of(long total, int pageSize, int currentPage, List<T> records) {
        return new PageResult<>(total, pageSize, currentPage, records);
    }
}
